package com.byxy.action;

import java.util.List;

import javax.annotation.Resource;

import com.byxy.entity.Category;
import com.byxy.entity.Product;
import com.byxy.service.CategoryService;
import com.byxy.service.ProductService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class IndexAction extends ActionSupport {
	
	private static final long serialVersionUID = 1L;
	// 1.注入一级分类
	@Resource
	private CategoryService categoryService;
	// 注入商品的Service
	@Resource
	private ProductService productService;

	@Override // 执行首页的方法
	public String execute() throws Exception {
		// 1. 查询所有一级分类集合
		List<Category> cList = categoryService.findAll();
		// 2.将一级分类存入到Session的范围:
		ActionContext.getContext().getSession().put("cList", cList);
		// 查询热门商品:
		List<Product> hList = productService.findHot();
		// 保存到值栈中:
		ActionContext.getContext().getValueStack().set("hList", hList);
		// 查询最新商品:
		List<Product> nList = productService.findNew();
		// 保存到值栈中:
		ActionContext.getContext().getValueStack().set("nList", nList);
		return SUCCESS;
	}

}
